package com.wili.extract_srcFile.java;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.c.Ca;
import com.wili.c.File9;
import _a.LogConf;
import javassist.ClassPool;
import javassist.NotFoundException;
/**
 * 	从执行路径上提取使用过的类和类方法。
 */
public class CodeExtract {
	static {
	}

	static final File DATA_FILE = new File(LogConf.ConfRoot, CodeExtract.class.getSimpleName());

	static final Map<Class<?>, RangesOfClsMember> DATA_MAP = new HashMap<>();

	static final List<RangesOfClsMember> DATA_LIST = new ArrayList<>(DATA_MAP.values());

	static final ClassPool ClsPool = ClassPool.getDefault();

	/**
	 * 	用来避免重复访问。
	 */
	static final Set<String> USED_METHOD_SET = new HashSet<>();

	static Set<Integer> LOG_ID_SET;

	/**
	 * 	
	 *  1. find Method by $clsName and $lineNo.
	 *  2. set usedMethod.visited = true
	 *  3. visit_all_called_method_inMethodList(..)
	 */
	static int inc3;
	public static void removeFile() {
		if (DATA_FILE.exists()) {
			if (DATA_FILE.delete()) {
				Ca.debug(1, "CollectUsedClassAndFuns.removeFile:" + DATA_FILE.getName());
			} else {
				Ca.debug(1, "Please remove file:" + DATA_FILE.getAbsolutePath());
			}
		}
	}

	public static void saveToFile() {
		if (!CodeExtract.saveToFile)
			return;
		if (DATA_MAP == null || DATA_MAP.isEmpty())
			return;
		if (savedVersionId == curVersionId)
			return;
		File9.writeObject(DATA_MAP, DATA_FILE, -1);
		savedVersionId = curVersionId;
		Ca.debug(1, "\n" + DATA_MAP.size() + " files, CodeExtract.saveToFile: " + DATA_FILE.getAbsolutePath());
	}

	public static void main(String[] args) throws NotFoundException {
	}
	public static boolean stopMe = false;

	public static boolean saveToFile = "".isEmpty();

	public static int savedVersionId, curVersionId;

	static int inc;
}
